/*
 * @Author: LG
 * @Date: 2020-11-12 10:20:34
 * @Description: 
 * @Last Modified By: LG
 * @Last Modified Time: 2020-11-12 10:54:08
 */
/**
 * @description 对象合并
 * @param  {...any} args 
 */
export const merge = (...args) => {
    return args.reduce((result, item) => {
        for (const key in item) {
            const current = item[key];
            result[key] = result.hasOwnProperty(key) && isObject(result[key]) ? merge(result[key], current) : current
        }
        return result
    }, {})
}
export const getType = v => Object.prototype.toString.call(v).slice(8, -1)
export const isObject = v => getType(v) === 'Object'
export const isArray = v => getType(v) === "Array" || Array.isArray(v)
export const isNumber = v => getType(v) === "Number"
export const isFunction = v => getType(v) === "Function"
export const isSymbol = v => getType(v) === "Symbol"
export const debounce = (fn, delay) => {
    let timer = null
    return () => {
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, arguments)
        }, delay);
    }
}
export const throttle = (fn, wait, delay) => {
    let timer = null, previous = null
    return () => {
        if (!previous) previous = Date.now()
        if (now - previous > wait) {
            fn.apply(this, arguments)
            previous = now
        } else {
            clearTimeout(timer)
            timer = setTimeout(() => {
                fn.apply(this, arguments)
            }, delay);
        }
    }
}
export const cloneDeep = v => JSON.parse(JSON.stringify(v))